package com.departmentstore.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;

@Data
@Entity
@Table(name = "manufacturer_product")
public class ManufacturerProduct implements Serializable {
    @EmbeddedId
    private ManufacturerProductId id;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("manufacturerId")
    @JoinColumn(name = "manufacturer_id")
    @JsonIgnore
    private Manufacturer manufacturer;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("productId")
    @JoinColumn(name = "product_id")
    @JsonIgnore
    private Product product;

    @Column(name = "price")
    private BigDecimal price;

    public String getManufacturerId() {
        return id != null ? id.getManufacturerId() : null;
    }

    public void setManufacturerId(String manufacturerId) {
        if (id == null) {
            id = new ManufacturerProductId();
        }
        id.setManufacturerId(manufacturerId);
    }

    public String getProductId() {
        return id != null ? id.getProductId() : null;
    }

    public void setProductId(String productId) {
        if (id == null) {
            id = new ManufacturerProductId();
        }
        id.setProductId(productId);
    }
}
